<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body {
            margin: 4px
        }

        .container {
            display: flex;
            flex-direction: column;
            flex-wrap: wrap;
            height: 2300px;
        }

        .item {
            width: 25%;
            padding: 2px;
            box-sizing: border-box;
            position: relative;
            counter-increment: item-idx
        }

        .item img {
            display: block;
            width: 100%;
            height: auto;
        }

        .item::after {
            width: 24px;
            height: 24px;
            line-height: 24px;
            text-align: center;
            color: #fff;
            background-color: #000;
            display: block;
            position: absolute;
            left: 2px;
            top: 2px;
            content: counter(item-idx)
        } 
        .item:nth-child(4n+1){
            order: 1
        }
        .item:nth-child(4n+2){
            order: 2
        }
        .item:nth-child(4n+3){
            order: 3
        }
        .item:nth-child(4n){
            order: 4
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="item">
            <img src="https://picsum.photos/360/460?random=1" alt="">
        </div>
        <div class="item">
            <img src="https://picsum.photos/360/500?random=1" alt="">
        </div>
        <div class="item">
            <img src="https://picsum.photos/360/480?random=1" alt="">
        </div>
        <div class="item">
            <img src="https://picsum.photos/360/400?random=1" alt="">
        </div>
        <div class="item">
            <img src="https://picsum.photos/360/520?random=1" alt="">
        </div>
        <div class="item">
            <img src="https://picsum.photos/360/420?random=1" alt="">
        </div>
        <div class="item">
            <img src="https://picsum.photos/360/490?random=1" alt="">
        </div>
        <div class="item">
            <img src="https://picsum.photos/360/550?random=1" alt="">
        </div>
        <div class="item">
            <img src="https://picsum.photos/360/460?random=1" alt="">
        </div>
        <div class="item">
            <img src="https://picsum.photos/360/440?random=1" alt="">
        </div>
        <div class="item">
            <img src="https://picsum.photos/360/460?random=1" alt="">
        </div>
        <div class="item">
            <img src="https://picsum.photos/360/500?random=1" alt="">
        </div>
        <div class="item">
            <img src="https://picsum.photos/360/480?random=1" alt="">
        </div>
        <div class="item">
            <img src="https://picsum.photos/360/400?random=1" alt="">
        </div>
        <div class="item">
            <img src="https://picsum.photos/360/520?random=1" alt="">
        </div>
        <div class="item">
            <img src="https://picsum.photos/360/420?random=1" alt="">
        </div> 
    </div>
</body>

</html>